package com.ymttest.database.sqlwapper.godmember;

import com.ymt.core.tool.FormatUtil;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.godmember.*;

import java.util.List;

public class GodMemberWapper {
	SqlManager manage;

	public GodMemberWapper() {
		manage = new SqlManager("mysqlgodmemberdbsit1");

	}
	
	/**
	 * 修改商家是否开启会员邀请制度
	 * @param ShopId
	 * @param NeedInvitationCode
	 * @return
	 * @throws InterruptedException
	 */
	public int updateMchmemberConfigNeedInvitationCode(Integer ShopId,Boolean NeedInvitationCode) throws InterruptedException {
		if(ShopId==null||NeedInvitationCode==null) {
			return 0;
		}
		MchMemberConfig MchMemberConfig=new MchMemberConfig();
		MchMemberConfig.setNeedInvitationCode(NeedInvitationCode);
		MchMemberConfig.setShopId(ShopId);
		int i = manage.update("com.ymttest.database.mapping.godmember.GodMemberMapper.updateMchmemberConfigNeedInvitationCode", MchMemberConfig);
		manage.commit();
		return i;
	}
	/**
	 * BizType（积分规则表）
	 * 
	 * @param MchId 
	 * @return
	 * @throws InterruptedException
	 */
	public BizType selectBizTypeByBizType(Integer BizType) throws InterruptedException {
		if(BizType==null) {
			return new BizType();
		}
		BizType list = (com.ymttest.database.model.godmember.BizType) manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectBizTypeByBizType", BizType).get(0);
		manage.commit();
		return list;
	}
	//selectMchMemberConfigByShopId
	/**MchMemberConfig（商户会员配置表）
	 * @param ShopId
	 * @return
	 * @throws InterruptedException
	 */
	public MchMemberConfig selectMchMemberConfigByShopId(Integer ShopId) throws InterruptedException {
		if(ShopId==null) {
			return new MchMemberConfig();
		}
		MchMemberConfig list = (com.ymttest.database.model.godmember.MchMemberConfig) manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectMchMemberConfigByShopId", ShopId).get(0);
		manage.commit();
		return list;
	}
	/**
	 * Memberid查询会员信息
	 * 
	 * @param memberid 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Member> selectMemberByMemberid(String memberid) throws InterruptedException {
		MemberExample pe = new MemberExample();
		pe.setOrderByClause("`UpdateTime` DESC");
		 com.ymttest.database.model.godmember.MemberExample.Criteria c = pe.createCriteria();
		 if(memberid!=null) {
			 c.andMemberIdEqualTo(memberid);
		 }else {
			 return null;
		 }
		List<Member> list = manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectMemberByExample", pe);
		manage.commit();
		return list;
	}
	
	/**
	 * Memberid查询会员信息
	 * 
	 * @param openid 
	 * @param shopId 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Member> selectMemberByOpenId(String openid,Integer shopId) throws InterruptedException {
		MemberExample pe = new MemberExample();
		pe.setOrderByClause("`UpdateTime` DESC");
		 com.ymttest.database.model.godmember.MemberExample.Criteria c = pe.createCriteria();
		 if(shopId!=null) {
			 c.andShopIdEqualTo(shopId);
		 }
		 if(openid!=null) {
			 c.andOpenIdEqualTo(openid);
		 }else {
			 return null;
		 } 
		List<Member> list = manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectMemberByExample", pe);
		manage.commit();
		return list;
	}
	/**
	 * Memberid查询会员信息
	 * 
	 * @param openid 
	 * @param shopId 
	 * @return
	 * @throws InterruptedException
	 */
	public List<Member> selectMemberByUserId(Integer userid,Integer shopId) throws InterruptedException {
		MemberExample pe = new MemberExample();
		pe.setOrderByClause("`UpdateTime` DESC");
		 com.ymttest.database.model.godmember.MemberExample.Criteria c = pe.createCriteria();
		 if(shopId!=null) {
			 c.andShopIdEqualTo(shopId);
		 }
		 if(userid!=null) {
			 c.andUserIdEqualTo(userid);
		 }else {
			 return null;
		 } 
		List<Member> list = manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectMemberByExample", pe);
		manage.commit();
		return list;
	}
	//selectMemberPointsByExample
	/**
	 * Memberid查询会员信息
	 * 
	 * @param openid 
	 * @param shopId 
	 * @return
	 * @throws InterruptedException
	 */
	public List<MemberPoints> selectMemberPointsByUserId(Integer userid,Integer shopId) throws InterruptedException {
		MemberPointsExample pe = new MemberPointsExample();
		pe.setOrderByClause("`UpdateTime` DESC");
		 com.ymttest.database.model.godmember.MemberPointsExample.Criteria c = pe.createCriteria();
		 if(shopId!=null) {
			 c.andShopIdEqualTo(shopId);
		 }
		 if(userid!=null) {
			 c.andUserIdEqualTo(userid);
		 }else {
			 return null;
		 } 
		List<MemberPoints> list = manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectMemberPointsByExample", pe);
		manage.commit();
		return list;
	}
	/**
	 * Memberid查询会员信息
	 * 
	 * @param openid 
	 * @param shopId 
	 * @return
	 * @throws InterruptedException
	 */
	public List<MemberPoints> selectMemberPointsByMemberId(String memberid) throws InterruptedException {
		MemberPointsExample pe = new MemberPointsExample();
		pe.setOrderByClause("`UpdateTime` DESC");
		 com.ymttest.database.model.godmember.MemberPointsExample.Criteria c = pe.createCriteria();
		 if(memberid!=null) {
			 c.andMemberIdEqualTo(memberid);
		 }else {
			 return null;
		 }
		List<MemberPoints> list = manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectMemberPointsByExample", pe);
		manage.commit();
		return list;
	}
	//selectPointsEntryByExample
	/**
	 * 查询用户积分记录
	 * @param memberid
	 * @return
	 * @throws InterruptedException
	 */
	public List<PointsEntry> selectPointsEntryByMemberid(String memberid) throws InterruptedException {
		PointsEntryExample pe = new PointsEntryExample();
		pe.setOrderByClause("`EntryId` DESC");
		  com.ymttest.database.model.godmember.PointsEntryExample.Criteria c = pe.createCriteria();
		 if(memberid!=null) {
			 c.andMemberIdEqualTo(memberid);
		 }else {
			 return null;
		 }
		List<PointsEntry> list = manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectPointsEntryByExample", pe);
		manage.commit();
		return list;
	}
	//selectPointsRuleByExample
	public List<PointsRule> selectPointsRuleByShopId(Integer shopid) throws InterruptedException {
		PointsRuleExample pe = new PointsRuleExample();
		pe.setOrderByClause("`UpdateTime` DESC");
		 com.ymttest.database.model.godmember.PointsRuleExample.Criteria c = pe.createCriteria();
		 if(shopid!=null) {
			 c.andShopIdEqualTo(shopid);
		 }else {
			 return null;
		 }
		List<PointsRule> list = manage.getSelectResults("com.ymttest.database.mapping.godmember.GodMemberMapper.selectPointsRuleByExample", pe);
		manage.commit();
		return list;
	}
	
	public int updateCDFToken(Long ShopId) throws InterruptedException {
		
		if (ShopId == null) {
			return 0;
		}

		int i = manage
				.update("com.ymttest.database.mapping.godmember.GodMemberMapper.updateCDFToken",
						ShopId);
		manage.commit();
		return i;
	}
	
	//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	
	public static void main(String args[]) throws InterruptedException {
		GodMemberWapper DefGodMemberWapper=new GodMemberWapper();
		
//		System.out.println(FormatUtil.beanToGSONString( DefGodMemberWapper.selectBizTypeByBizType(100000)));
//		System.out.println(FormatUtil.beanToGSONString( DefGodMemberWapper.selectMchMemberConfigByShopId(50001)));
//		System.out.println(FormatUtil.beanToGSONString( DefGodMemberWapper.selectMemberByMemberid("13011111111")));
//		System.out.println(FormatUtil.beanToGSONString( DefGodMemberWapper.selectMemberByOpenId("aaaaaa",50001)));
//		System.out.println(FormatUtil.beanToGSONString( DefGodMemberWapper.selectMemberByUserId(222,50001)));
//		System.out.println(FormatUtil.beanToGSONString( DefGodMemberWapper.selectMemberPointsByMemberId("HY2020051800094")));
//		System.out.println(FormatUtil.beanToGSONString( DefGodMemberWapper.selectMemberPointsByUserId(222,50001)));
//		//selectPointsRuleByShopId
//		System.out.println(FormatUtil.beanToGSONString( DefGodMemberWapper.selectPointsRuleByShopId(50001)));
//		System.out.println(DefGodMemberWapper.updateMchmemberConfigNeedInvitationCode(50001,true));
		System.out.println(DefGodMemberWapper.updateCDFToken(502060981L));
	}
}
